package nuc.soft.A01.jzs.services.problem;

import java.util.ArrayList;

import nuc.soft.A01.jzs.dao.problem.ManyChooseMapper;
import nuc.soft.A01.jzs.model.problem.ManyChooseProblem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tool.Tools;


@Service
public class ManyChooseService {

	@Autowired
	private ManyChooseMapper dao;
	
	public int insert(ManyChooseProblem problem)
	{
		problem.setId(Tools.getUUID());
		return dao.insert(problem);
	}
	
	public int update(ManyChooseProblem problem)
	{
		return dao.update(problem);
	}
	
	public int delete(ManyChooseProblem problem)
	{
		return dao.delete(problem);
	}
	
	public int deleteById(String id)
	{
		return dao.deleteById(id);
	}
	
	public int deleteById(ManyChooseProblem problem)
	{
		return dao.deleteById(problem.getId());
	}
	
	public ArrayList<ManyChooseProblem>	getAllManyChoose()
	{
		return (ArrayList<ManyChooseProblem>) dao.getAllObject();
	}
	
	public ArrayList<ManyChooseProblem> getSearchManyChoose(String search)
	{
		ArrayList<ManyChooseProblem> allproblem=this.getAllManyChoose();
		ArrayList<ManyChooseProblem> searchproblem=new ArrayList<ManyChooseProblem>();
		for(ManyChooseProblem problem:allproblem)
		{
			if(problem.getQuestion().contains(search))
			{
				searchproblem.add(problem);
			}
		}
		return searchproblem;
	}
	
	public ManyChooseProblem getAManyChooseById(String id)
	{
		return (ManyChooseProblem) dao.getAObjectById(id);
	}
}
